"""
Find api
"""


import json

from .command import raw_command
from .argument import build_args
from redfishtoollib import main


# get system fru info
def system_info():
    args = build_args()
    cmd = raw_command(args, 'GET', '/redfish/v1/Systems', None)
    res = main(cmd)
    try:
        urls = json.loads(res)
    except ValueError:
        urls = {}
    if len(urls.get('Members', [])) > 0:
        cmd = raw_command(args, 'GET', urls.get('Members', [])[0].get('@odata.id'), None)
        res = main(cmd)
        try:
            fru = json.loads(res)
        except ValueError:
            fru = {}
        print(json.dumps({
            'Manufacturer': fru.get('Manufacturer'),
            'Model': fru.get('Model'),
            'SerialNumber': fru.get('SerialNumber')
        }, indent=4))